﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace ConexionBD
{
    public partial class FormVerNot2 : Form
    {
        MySqlConnection Conexion = new MySqlConnection();
        public string stConsulta;
        string opcion1;
        string opcion2;
        public FormVerNot2()
        {
            InitializeComponent();
        }

        private void FormVerNot2_Load(object sender, EventArgs e)
        {
            Nota nnn = new Nota();
            DataTable dt = new DataTable();
            dt = nnn.mandaUno();

    

            try
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                    comboBox1.Items.Add(dt.Rows[i]["nombre_libreta"]);
            }

            catch(MySqlException error)
            {
                throw error;
            }
          /*  finally
            {
                Conexion.Close();
            } */
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Nota notag = new Nota();
            int selectedIndex = comboBox1.SelectedIndex;
            Object selectedItem = comboBox1.SelectedItem;
            opcion1 = selectedItem.ToString();
            
            DataTable dt2 = new DataTable();
            

           
            dt2 = notag.llenarCombo2(opcion1);
            try
            {
                for (int i = 0; i < dt2.Rows.Count; i++)
                    comboBox2.Items.Add(dt2.Rows[i]["titulo"]);
            }

            catch (MySqlException error)
            {
                throw error;
            }
        }

       /* public void llenarCombo2(string opcion1)
        {
            opcion1 = "'" + opcion1 + "'";
            
            MySqlDataAdapter sql2 = new MySqlDataAdapter("Select n.titulo from nota n, libreta l where n.id_libreta = l.id_libreta and l.nombre_libreta = " + opcion1, Conexion);
            DataTable dt2 = new DataTable();
            sql2.Fill(dt2);

            try
            {
                for (int i = 0; i < dt2.Rows.Count; i++)
                    comboBox2.Items.Add(dt2.Rows[i]["titulo"]);
            }

            catch (MySqlException error)
            {
                throw error;
            }
        
        }*/

        private void button2_Click(object sender, EventArgs e)
        {
            Nota notax = new Nota();
            int selectedIndex2 = comboBox2.SelectedIndex;
            Object selectedItem2 = comboBox2.SelectedItem;
            opcion2 = selectedItem2.ToString();
            DataTable dt3 = new DataTable();
            dt3 = notax.verTexto(opcion2);

         

           /* opcion2 = "'" + opcion2 + "'";
            MySqlDataAdapter sql3 = new MySqlDataAdapter("Select texto from nota where titulo = " + opcion2, Conexion);
            DataTable dt3 = new DataTable();
            sql3.Fill(dt3);
            * */
            richTextBox1.Text = dt3.Rows[0]["texto"].ToString();

            
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
    }
}
